package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import com.itany.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Author：侍家宇
 * Date：2019-09-25 下午6:24
 * Description：<描述>
 */

@Controller
@RequestMapping("/permission")
public class permissionController {
    @Autowired
    private PermissionService permissionService;


    /**
     * 查询所有
     * @param page
     * @param rows
     * @return
     */

@RequestMapping("/findAllPermission")
@ResponseBody
public Map<String, Object> findAllPermission( @RequestParam(defaultValue = "1")Integer page,
                                           @RequestParam(defaultValue = "10")Integer rows) {
    Map<String, Object> map = new HashMap<String, Object>();
    PageInfo<Permission> info = permissionService.findAllPermission(page,rows);
    map.put("total", info.getTotal());
    map.put("rows", info.getList());
    return map;
}

    /**
     * 修改前查询
     * @param id
     * @return
     */
    @RequestMapping("findpermission")
    @ResponseBody
    public AjaxResult findpermission(Integer id){
    AjaxResult result = new AjaxResult();

    try {
        Permission permission=permissionService.findpermission(id);
        result.setObj(permission);
        result.setSuccess(true);
        result.setMsg("成功");
    } catch (Exception e) {
        e.printStackTrace();
        result.setSuccess(false);
        result.setMsg("服务器异常");
    }
    return result;
}
    /**
     * 修改
     */
    @RequestMapping("/modifyPermission")
    public String modifyPermission(Permission permission){

        try {
            permissionService.modifyPermission(permission);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "redirect:/manager/showpermission";
    }

}
